<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>feval</title>
<style type="text/css">
	body {background-color: white; color: black; font-family:sans-serif; font-size:medium;}
	a:link {color: #3300ff;}
	a:visited {color: #663399;}
	a:hover {color:#0099ff;}
	a:active {color: #0066cc;}
	a.button {text-decoration:none;}
	
	table.nav  {background-color: #dbddff;}
	table.body {margin-top:2ex; margin-bottom:2ex;}
	table.programlistingindent {margin-left:32px;}
	
	img { margin-bottom:0px; margin-top:0px;}
	tt {margin-left:0.5em; margin-right:0.5em; font-weight:lighter;}
	
	p {margin-top:0ex;}
	p.synopsis {margin-left:32px;}
	p.programlistingindent {margin-left:32px;}
	p.citetitle {margin-left:2em;}
	
	ul ul {list-style-type:square;}
	ul li p {margin-top:0ex; margin-bottom:.5ex; padding:0}
	ol li p {margin-top:0ex; margin-bottom:.5ex; padding:0}
	
	h1.reftitle {color:#a90000;}
	h1.reftitle {font-size:3.7ex; margin-top:0; margin-bottom:0; font-weight:bold}
	h1.title {color:black; font-size:4ex; margin-top:1ex; font-weight:bold}
	h2.title {color:#bd0000; margin-top:1ex; margin-bottom:.9ex; font-weight:bold; font-size:3ex}
	h3.title {color:#bd0000; margin-top:1ex; margin-bottom:.9ex; font-weight:bold; font-size:2.5ex}
	h4.title {color:#bd0000; margin-top:1ex; margin-bottom:.9ex; font-weight:bold; font-size:2ex}
	h2 {color:#bd0000; margin-top:1ex; margin-bottom:.9ex; font-weight:bold; font-size:2.5ex}
	h3 {color:#bd0000; margin-top:1ex; margin-bottom:.9ex; font-weight:bold; font-size:2ex} 
	
	pre.programlisting {margin-left:32px;}
	pre.synopsis {margin-left:32px;}
	
	
	.categorytitle {margin-top:8px; padding-top:0px;}
	.categorylist {background-color: #e1e6f2;}
 	</style>
</head>
<body>
<a name="top_of_page"></a><p style="font-size:1px;"></p>
<h1 class="reftitle">feval</h1>
<h2>Purpose</h2>
<p>Evaluates a function defined over a convex set or an array thereof.</p>
<h2>Syntax</h2>
<pre class="synopsis">[fval, feasible] = Set.feval(x)</pre>
<pre class="synopsis">[fval, feasible] = Set.feval(x,function_name)</pre>
<pre class="synopsis">[fval, feasible] = feval(Set,x,function_name)</pre>
<h2>Description</h2>
<p></p>
        Evaluates function for given value of the point <tt>x</tt> over the convex <tt>Set</tt> characterized
        by the the string <tt>function_name</tt>.
        The dimension of the vector <tt>x</tt> must be the same as the dimension of the <tt>Set</tt>.
        If the <tt>Set</tt> is an array of convex sets, the function values are
        returned in an array. For a point that lies outside of the <tt>Set</tt>, the output is <tt>NaN</tt>.
	<h2>Input Arguments</h2>
<table cellspacing="0" class="body" cellpadding="4" border="0" width="100%">
<colgroup>
<col width="31%">
<col width="69%">
</colgroup>
<tbody>
<tr valign="top">
<td><tt>Set</tt></td>
<td>
<p></p>Convex set or an array thereof, i.e. any object derived from the <tt>ConvexSet</tt> class, e.g. <tt>Polyhedron</tt>, <tt>YSet</tt>, ...<p>
	    		Class: <tt>ConvexSet</tt></p>
</td>
</tr>
<tr valign="top">
<td><tt>x</tt></td>
<td>
<p></p>A point at which the function should be evaluated. The point must be given as column and must be in the same dimension as the set.<p>
	    		Class: <tt>double</tt></p>
</td>
</tr>
<tr valign="top">
<td><tt>function_name</tt></td>
<td>
<p></p>String name of the function to evaluate. It must refer
                   to a single function. If omitted, <tt>S.feval(x)</tt> only
                works if the set has a single function. 
        <p>
	    		Class: <tt>char</tt></p>
</td>
</tr>
</tbody>
</table>
<h2>Output Arguments</h2>
<table cellspacing="0" class="body" cellpadding="4" border="0" width="100%">
<colgroup>
<col width="31%">
<col width="69%">
</colgroup>
<tbody>
<tr valign="top">
<td><tt>fval</tt></td>
<td>
<p></p>An <img src="../../../../../../fig/mpt/modules/geometry/sets/@ConvexSet/feval1.png" alt="../../../../../../fig/mpt/modules/geometry/sets/@ConvexSet/feval1.png"> matrix of function values at <tt>x</tt>, where <img src="../../../../../../fig/mpt/modules/geometry/sets/@ConvexSet/feval2.png" alt="../../../../../../fig/mpt/modules/geometry/sets/@ConvexSet/feval2.png"> is the number
            of sets. If <tt>x</tt> is not contained in the <img src="../../../../../../fig/mpt/modules/geometry/sets/@ConvexSet/feval3.png" alt="../../../../../../fig/mpt/modules/geometry/sets/@ConvexSet/feval3.png">-th set, then the <img src="../../../../../../fig/mpt/modules/geometry/sets/@ConvexSet/feval4.png" alt="../../../../../../fig/mpt/modules/geometry/sets/@ConvexSet/feval4.png">-th
        column of <tt>fval</tt> is a vector of <tt>NaN</tt>.<p>
	    		Class: <tt>double</tt></p>
</td>
</tr>
<tr valign="top">
<td><tt>feasible</tt></td>
<td>
<p></p>An <img src="../../../../../../fig/mpt/modules/geometry/sets/@ConvexSet/feval5.png" alt="../../../../../../fig/mpt/modules/geometry/sets/@ConvexSet/feval5.png"> vector of logicals. <tt>feasible(j)=true</tt> if the <img src="../../../../../../fig/mpt/modules/geometry/sets/@ConvexSet/feval6.png" alt="../../../../../../fig/mpt/modules/geometry/sets/@ConvexSet/feval6.png">-th
                element of the array contains <tt>x</tt>.
        <p>
	    		Class: <tt>double</tt></p>
</td>
</tr>
</tbody>
</table>
<h2>Example(s)</h2>
<h3>Example 
				1</h3> Evaluate a function over a simple polytope.  Construct the polytope in H-representation<pre class="programlisting"> P = Polyhedron('lb',[-1;-2],'ub',[1;2]); </pre>
<pre class="programlisting"></pre> Assign a quadratic function to it <pre class="programlisting"> Q = QuadFunction([1 2;-2 3],[0 -5],0.6) </pre>
<pre class="programlisting">Quadratic Function: R^2 -&gt; R^1
</pre>
<pre class="programlisting"> P.addFunction(Q,'q'); </pre>
<pre class="programlisting"></pre> Obtain the value of the function for the point [-1;-1.5] <pre class="programlisting"> x = [-1; -1.5];</pre>
<pre class="programlisting"></pre>
<pre class="programlisting"> y = P.feval(x)</pre>
<pre class="programlisting">
y =

                     15.85

</pre> We can plot the function over the set with the point [x,y] <pre class="programlisting"> P.fplot; hold on;  text(x(1),x(2),y,'\bf{x}','FontSize',14); </pre>
<pre class="programlisting"></pre>
<p class="programlistingindent"><img src="../../../../../../fig/mpt/modules/geometry/sets/@ConvexSet/feval_img_1.png" alt="../../../../../../fig/mpt/modules/geometry/sets/@ConvexSet/feval_img_1.png" width="60%"></p>
<h3>Example 
				2</h3> We have three linear functions "a", "b", and "c" over unbounded polyhedron <tt>P</tt>.<pre class="programlisting"> P = Polyhedron([1 2;-0.6 8; 0 0.4; 5 -1],[1;2;0.7;0.01]) </pre>
<pre class="programlisting">Polyhedron in R^2 with representations:
    H-rep (redundant)   : Inequalities   4 | Equalities   0
    V-rep               : Unknown (call computeVRep() to compute)
Functions : none
</pre>
<pre class="programlisting"> F1 = AffFunction([1 2]) </pre>
<pre class="programlisting">Affine Function: R^2 -&gt; R^1
</pre>
<pre class="programlisting"> F2 = AffFunction([3 4; -1 0]) </pre>
<pre class="programlisting">Affine Function: R^2 -&gt; R^2
</pre>
<pre class="programlisting"> F3 = AffFunction([5 6; 7 8; 9 -1]) </pre>
<pre class="programlisting">Affine Function: R^2 -&gt; R^3
</pre> Add functions to a polyhedron with corresponding names in a cell array.<pre class="programlisting"> P.addFunction(F1, 'a') </pre>
<pre class="programlisting">Polyhedron in R^2 with representations:
    H-rep (redundant)   : Inequalities   4 | Equalities   0
    V-rep               : Unknown (call computeVRep() to compute)
Functions : 1 attached "a"
</pre>
<pre class="programlisting"> P.addFunction(F2, 'b') </pre>
<pre class="programlisting">Polyhedron in R^2 with representations:
    H-rep (redundant)   : Inequalities   4 | Equalities   0
    V-rep               : Unknown (call computeVRep() to compute)
Functions : 2 attached "a", "b"
</pre>
<pre class="programlisting"> P.addFunction(F3, 'c') </pre>
<pre class="programlisting">Polyhedron in R^2 with representations:
    H-rep (redundant)   : Inequalities   4 | Equalities   0
    V-rep               : Unknown (call computeVRep() to compute)
Functions : 3 attached "a", "b", "c"
</pre> Evaluate function "a" for the point [-1;-1] <pre class="programlisting"> P.feval([-1;-1],'a') </pre>
<pre class="programlisting">
ans =

    -3

</pre> Evaluate functions "b" and "c" for the point [-1;-1] <pre class="programlisting"> y1 = P.feval([-1;-1],'b') </pre>
<pre class="programlisting">
y1 =

    -7
     1

</pre>
<pre class="programlisting"> y2 = P.feval([-1;-1],'c') </pre>
<pre class="programlisting">
y2 =

   -11
   -15
    -8

</pre>
<h2>See Also</h2>
<a href="./fplot.html">fplot</a>, <a href="../../functions/@Function/function.html">function</a><p></p>
<table class="nav" summary="Navigation aid" border="0" width="100%" cellpadding="0" cellspacing="0"><tr valign="top">
<td align="left" width="20">
<a href="fliplr.html" class="button">&#9664;</a>  </td>
<td align="left">fliplr</td>
<td>  </td>
<td align="right">isbounded</td>
<td align="right" width="20"><a href="isbounded.html" class="button">&#9654;</a></td>
</tr></table>
<br><p>©  <b>2010-2013</b>     Martin Herceg: ETH Zurich,    <a href="mailto:herceg@control.ee.ethz.ch">herceg@control.ee.ethz.ch</a></p>
<p>©  <b>2003-2013</b>     Michal Kvasnica: STU Bratislava,    <a href="mailto:michal.kvasnica@stuba.sk">michal.kvasnica@stuba.sk</a></p>
</body>
</html>
